//
//  ViewController.m
//  Study
//
//  Created by startiasoft on 2020/2/26.
//  Copyright © 2020 Startiasoft. All rights reserved.
//

#import "ViewController.h"
#import "SignInWithAppleViewController.h"
#import "ApplePayViewController.h"

#import <WebKit/WebKit.h>
static NSString *cellID = @"cell";
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic , strong) NSArray *titleArray;
@end

@implementation ViewController


#pragma mark Init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray = @[@"Sign in with Apple",@"Apple Pay"];
    }
    return _titleArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"StudyDemo";
    
    //[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    
//    WKWebView *webView = [[WKWebView alloc] init];
//    webView.frame = self.view.frame;
//    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com"]]];
//    [self.view addSubview:webView];
    
}


#pragma mark Table Delegate Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    cell.textLabel.text = self.titleArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat cellHeight = [UIScreen mainScreen].bounds.size.height;
    return cellHeight/12;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0:
        {
            SignInWithAppleViewController *signVC = [[SignInWithAppleViewController alloc] init];
            [self.navigationController pushViewController:signVC animated:YES];
        }
            break;
        case 1:
        {
            ApplePayViewController *payVC = [[ApplePayViewController alloc] init];
            [self.navigationController pushViewController:payVC animated:YES];
        }
            break;
            
        default:
            break;
    }
    
}

@end

